<?php
    $this->pageHeader = t('PAGE_TITLE', 'article');
    $this->pageTitle = t('PAGE_TITLE', 'article');

    //Create tool bar
    $toolbar = new LGToolbar();
    
    $toolbar->buttonNewPage(t('PAGE_TITLE_ADDNEW', 'article'), '', app()->controller->id . '/create');
    $toolbar->buttonConfirm(t('BTN_CHECK_IN'), t('BTN_CHECK_IN'), app()->controller->id . '/checkin');

    //If filtering status is Trash, change 'Trash' button to 'Delete' button.
    // Else show 'Trash' button
    if ($model->status == LGConstantArticleStatus::TRASHED) {
	$toolbar->buttonConfirm(t('BTN_DELETE'), t('BTN_DELETE'), app()->controller->id . '/delete');
    } else {
	$toolbar->buttonConfirm(t('BTN_TRASH'), t('BTN_TRASH'), app()->controller->id . '/trash');
    }

    $toolbar->buttonRefresh(t('BTN_REFRESH'), t('BTN_REFRESH'), url(app()->controller->id . '/refresh'));
    $this->pageToolbar = $toolbar->mergeToolbar();

    //Create breadcrumbs
    $this->breadcrumbs = array(t('MENU_MANAGEMENT'), t('LBL_ARTICLE', 'article') => array('index'));
?>
<!-- search-form -->
<div class="search-form" >
    <?php
    $this->renderPartial('_search', array(
        'model' => $model,
    ));
    ?>
</div>

<!-- grid -->
<?php
$this->widget('GridView', array(
    //Update titlebar when update gridview, to change Delete, Trash button
     'afterAjaxUpdate' => 'function refreshButtonDeleteStatus (id, data) {
	$("#titlebar").html($("#titlebar", data).html());
    }',
    'id' => 'DataGrid',
    'dataProvider' => $model->search(),
    'summaryText'=> LGHelpers::getSummary(),
    'columns' => array(
        array(
            'header' => '#',
            'class' => 'CCheckBoxColumn',
            'selectableRows' => '2',
            'id' => 'chkId',
        ),
        array(
            'header' => t('LBL_TITLE', 'article'),
            'htmlOptions' => array('width' => '199px'),
            'name' => 'title',
            'value' => 'Html::linkCheckOutInGrid($data->id,CHtml::encode($data->title),$data->checkout)',
            'type' => 'raw',
        ),
        array(
            'header' => t('LBL_STATUS', 'article'),
            'htmlOptions' => array('width' => '57px', 'align' => 'center'),
            'name' => 'status',
            'value' => 'Html::active($data->id,$data->status, "status")',
            'type' => 'raw',
        ),
        array(
            'header' => t('LBL_FEATURED', 'article'),
            'htmlOptions' => array('width' => '57px', 'align' => 'center'),
            'name' => 'featured',
            'value' => 'Html::active($data->id,$data->featured, "featured", "Featured", "UnFeatured", "icon featured","icon disabled")',
            'type' => 'raw',
        ),
        array(
            'header' => t('LBL_CATEGORY', 'article'),
            'name' => 'catid',
            'value' => '$data->cat->name',
            'htmlOptions' => array('width' => '114px', 'align' => 'center'),
        ),
//        array(
//            'header' => t('LBL_COMMENT', 'article'),
//            'htmlOptions' => array('width' => '57px', 'align' => 'center'),
//            'name' => 'can_comment',
//            'value' => 'Html::active($data->id,$data->can_comment, "comment", "Allow Comment", "Don\'t Allow Comment","icon active","icon disabled")',
//            'type' => 'raw',
//        ),
        array(
            'name' => 'updated_by',
             'htmlOptions' => array('width' => '57px', 'align' => 'center'),
        ),
        array(
            'name' => 'update_date',
             'htmlOptions' => array('width' => '87px', 'align' => 'center'),
            'sortable' => TRUE,
        ),
        array(
            'name' => 'id',
           'htmlOptions' => array('width' => '43px', 'align' => 'center'),
        ),
        array(
            'name' => 'hits',
 'htmlOptions' => array('width' => '43px', 'align' => 'center'),
	    ),
        array(
            'name' => 'language',
            'htmlOptions' => array('align' => 'center'),
            'value' => 'LGHelpers::getLanguage($data->language)',
	     'htmlOptions' => array('width' => '57px', 'align' => 'center'),
        ),
        array(
            'header' => t('LBL_ACTION', 'article'),
            'class' => 'ArticleButtonColumn',
            'template' => "{update}{restore}{delete_forever}",
	   //  lock 'Comment' function
	   //  'template' => "{update}{restore}{delete_forever}{view_comment}",
            'htmlOptions' => array('width' => '71px', 'align' => 'center'),
            'buttons' => array(
                'update' => array('title' => t('LBL_EDIT_ARTICLE', 'article'), 'url' => 'url("article/update/",array("id"=>$data->id))', 'isTrash' => '$data->status', 'canComment' => '$data->can_comment'),
                'restore' => array('title' => t('LBL_RESTORE_ARTICLE', 'article'), 'url' => 'url("article/restore/",array("id"=>$data->id))', 'isTrash' => '$data->status', 'canComment' => '$data->can_comment'),
                'delete_forever' => array('title' => t('LBL_DELETE_FOREVER_ARTICLE', 'article'), 'url' => 'url("article/delete/",array("id"=>$data->id))', 'isTrash' => '$data->status', 'canComment' => '$data->can_comment'),
                'view_comment' => array('title' => t('LBL_VIEW_COMMENT_ARTICLE', 'article'), 'dialog-width' => '900', 'dialog-height' => '600', 'url' => 'url("article/viewComment/",array("id"=>$data->id))', 'isTrash' => '$data->status', 'canComment' => '$data->can_comment'),
            )
        ),
    ),
));
?>
<script type="text/javascript">    
    $(document).ready(function(){
        ShowTooltip($(".locked"), $("#shareit-box"), "<?php echo url("article/getLockedTooltip"); ?>");
    });
    
</script>
    <?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog  
    'id' => 'dialogClassroom',
    'options' => array(
        'title' => t('LBL_LOGIGEAR_CMS'),
        'autoOpen' => false,
        'modal' => true,
        'width' => 350,
        'height' => 180,
    ),
));
?>  

<div id="update-dialog-message-plus" style="margin:15px 0 20px; text-align: center">
</div>
<div id="update-dialog-buttons-plus" style="text-align: center;">
</div>
<?php  $this->endWidget(); ?>  